package com.prd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.config.LoginInterceptor;
import com.prd.mapper.EntNarrationCaseMapper;
import com.prd.model.EntNarrationCase;
import com.prd.model.LoginUser;
import com.prd.service.EntNarrationCaseService;
import com.prd.util.UserInfoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EntNarrationCaseServiceImpl extends ServiceImpl<EntNarrationCaseMapper, EntNarrationCase> implements EntNarrationCaseService {

    @Autowired
    private EntNarrationCaseMapper entNarrationCaseMapper;

    @Override
    public int insertInfo(EntNarrationCase entNarrationCase) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), true), entNarrationCase);
        return entNarrationCaseMapper.insert(entNarrationCase);
    }

    @Override
    public int updateInfo(EntNarrationCase entNarrationCase) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), false), entNarrationCase);
        return entNarrationCaseMapper.updateById(entNarrationCase);
    }
}
